package com.wufun.overseas.main.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wufun.overseas.R;
import com.wufun.overseas.models.bean.IntentDateBean;

import butterknife.Bind;
import butterknife.ButterKnife;

public class SetWebViewActivity extends AppCompatActivity implements View.OnClickListener {

    @Bind(R.id.ll_bar_back)
    LinearLayout ll_bar_back;
    @Bind(R.id.ll_bar_more)
    LinearLayout ll_bar_more;
    @Bind(R.id.tv_title_bar)
    TextView tv_title;
    @Bind(R.id.webview)
    WebView mWebView;

    private int type;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_web_view);
        ButterKnife.bind(this);
        ll_bar_back.setOnClickListener(this);
        tv_title.setText("5 Fun all-in-one emulator");
        Intent intent = getIntent();

        String url = intent.getStringExtra("url");
        type=intent.getIntExtra("type",0);

        if (type==0){
            WebSettings setTtings = mWebView.getSettings();

            setTtings.setJavaScriptEnabled(true);
            setTtings.setCacheMode(WebSettings.LOAD_NO_CACHE);
            setTtings.setSupportZoom(true);
            mWebView.loadUrl(url);
            mWebView.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);
                    return true;
                }
            });
        }


    }

    public static Intent buildIntent(Context context, String url) {
        Intent intent = new Intent(context, SetWebViewActivity.class);
        intent.putExtra("url", url);
        return intent;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_bar_back:
                Log.e("TAG", "SS");
                finish();
                break;

        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        if (keyCode==event.KEYCODE_BACK){
//          if (mWebView.canGoBack()){
//             mWebView.goBack();
//             return true;
//          }else{
//              SetWebViewActivity.this.finish();
//          }
//        }

        return super.onKeyDown(keyCode, event);

    }
}
